package com.example.ovulationperiodtracker.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.ovulationperiodtracker.R;
import com.example.ovulationperiodtracker.databinding.ViewXinqingBinding;
import com.example.ovulationperiodtracker.utils.Constants;
import com.example.ovulationperiodtracker.utils.MyLog;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.tencent.mmkv.MMKV;

import java.util.ArrayList;

public class XinQingView extends FrameLayout {

    int[] iconSelectIds = {R.drawable.test_transparent,R.mipmap.xq11, R.mipmap.xq21, R.mipmap.xq31, R.mipmap.xq41, R.mipmap.xq51, R.mipmap.xq61};

    int[] iconUnselectIds = {R.drawable.test_transparent,R.mipmap.xq10, R.mipmap.xq20, R.mipmap.xq30, R.mipmap.xq40, R.mipmap.xq50, R.mipmap.xq60};
    String[] titles = {"","开心", "愤怒", "良好", "恐慌", "无精打采", "难过"};

    private ViewXinqingBinding binding;

    public XinQingView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        binding = ViewXinqingBinding.inflate(LayoutInflater.from(context), this, true);


        ArrayList<CustomTabEntity> tabEntities = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            tabEntities.add(new TabEntity("", iconSelectIds[i], iconUnselectIds[i]));
        }
        binding.xinqingLayout.setTabData(tabEntities);
        binding.xinqingLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                if (position != 0) {
                    String xinqing = titles[position];
                    Toast.makeText(context, xinqing, Toast.LENGTH_SHORT).show();
                    if (onXinQingListener != null) {
                        onXinQingListener.onClickXinQing(xinqing, position);
                    }
                }
            }

            @Override
            public void onTabReselect(int position) {
                // 如果需要处理重复点击同一个Tab的事件，可以在这里实现
            }
        });

    }


    public void setXinQing(int position) {
        if (position != -1) {
            binding.xinqingLayout.setCurrentTab(position);
        }

    }


    private OnXinQingListener onXinQingListener;

    public XinQingView setOnXinQingListener(OnXinQingListener onXinQingListener) {
        this.onXinQingListener = onXinQingListener;
        return this;
    }

    public interface OnXinQingListener {
        void onClickXinQing(String content, int position);
    }
}
